package tests;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class LayoutManagerTest extends JFrame {
	LayoutManagerTest() {
		setLayout(new GridBagLayout());
		ButtonGroup buttonGroup = new ButtonGroup();
		JDialog dialog=new JDialog(this);
		dialog.add(new JLabel("???"));

		for (int i = 0; i < 6; i++) {
			GridBagConstraints constraints = new GridBagConstraints();
			constraints.gridx = 0;
			constraints.gridy = i;
			JRadioButton button = new JRadioButton(String.valueOf(i));
			buttonGroup.add(button);
			button.addMouseListener(new ListenerTest(
					"You Just Chose " + i));
			add(button, constraints);
		}
		for (char c = 'a'; c < 'd'; c++) {
			GridBagConstraints constraints = new GridBagConstraints();
			constraints.gridx = 1;
			constraints.gridy = c - 'a';
			JPanel panel = new JPanel();
			panel.addMouseListener(new ListenerTest(
					"You Just Entered " + c));
			panel.add(new JLabel(String.valueOf(c)));
			panel.add(new JTextArea((char) (c + 1) + "         "));
			add(panel, constraints);
		}
		setSize(0x100, 0x100);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	public static void main(String[] args) {
		new LayoutManagerTest().setVisible(true);
	}

	class ListenerTest extends MouseAdapter {
		String prompt;

		public ListenerTest(String prompt) {
			this.prompt = prompt;
		}

		@Override
		public void mouseClicked(MouseEvent e) {
			JOptionPane.showMessageDialog(
					LayoutManagerTest.this, prompt);
		}
	}
}
